﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_Admin_DSJCJ.Common;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    public class FtpCodeController : Controller
    {
        //
        // GET: /Admin/FtpCode/

        public ActionResult Index()
        {
            string codeClsNo = "SYS_FTP";
            List<Model.SysBasicCodeName> codeNameList = new List<Model.SysBasicCodeName>();

            if (null != codeClsNo)
            {
                ViewData["blcode"] = true;
                ViewData["clsTitle"] = "编码类别： " + GetClsName(codeClsNo);
                codeNameList = GetCodeNameList(codeClsNo);
            }
            else
            {
                ViewData["blcode"] = false;
                ViewData["clsTitle"] = "请选择具体编码类别";
            }


            ViewData["codeClsNo"] = codeClsNo;

            return View(codeNameList);
    
        }
        public ActionResult CodeEdit(string codeClsNo, string codeNo)
        {
            Model.SysBasicCodeName codeNameObj = new Model.SysBasicCodeName();
            ViewData["blcodeNo"] = true;
            codeClsNo = Fetch.estimateString(codeClsNo, CheckGetEnum.Safety);
            if (null != codeClsNo && null != codeNo)
            {
                codeNo = Fetch.estimateString(codeNo, CheckGetEnum.Safety);
                BLL.SysBasicCodeName codeNameBll = new BLL.SysBasicCodeName();
                codeNameObj = codeNameBll.GetModel(codeClsNo, GlobalConstant.ENTITYNO, codeNo);
                if (null == codeNameObj)
                {
                    codeNameObj = new Model.SysBasicCodeName();
                }
                else
                {
                    ViewData["blcodeNo"] = false;
                }
            }
            else
            {
                codeNameObj.FCodeClsNo = codeClsNo;
            }

            return View(codeNameObj);
        }

        public ActionResult CodeListPartial()
        {
            List<Model.SysBasicCodeName> codeNameList = new List<Model.SysBasicCodeName>();
            string codeClsNo = Request.Params["codeClsNo"] == null ? string.Empty : Request.Params["codeClsNo"];
            if (codeClsNo != "")
            {
                codeNameList = GetCodeNameList(codeClsNo);
            }
            ViewData["blcode"] = true;
            return PartialView("CodeListPartial", codeNameList);
        }
        private List<Model.SysBasicCodeName> GetCodeNameList(string codeClsNo)
        {
            
            BLL.SysBasicCodeName codeNameBll = new BLL.SysBasicCodeName();
            return codeNameBll.GetListByClsNo(codeClsNo, GlobalConstant.ENTITYNO);
        }

        private string GetClsName(string clsNo)
        {
    
            BLL.SysBasicCodeCls codeClsBll = new BLL.SysBasicCodeCls();
            return codeClsBll.GetCodeClsName(clsNo);
        }
         public string ExistsFtpTypeCodeNo(string FFTPType)
        {
            BLL.SysBasicCodeName codeNameBll = new BLL.SysBasicCodeName();
            bool b = codeNameBll.ExistsFtpTypeCodeNo(FFTPType);
            if (b)
            {
                return "yes";
            }
            else
            {
                return "no";
               
            }
        }
    }
}
